package com.yj.util;

import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public abstract class AbstractProcessService<T, R> implements ProcessService<T, R> {
    @Override
    public R process(T t) throws Exception {

        log.info("Processing params: {}", t.getClass().getSimpleName());

        // 校验参数
        volidateParams(t);

        // 业务逻辑处理
        R result = doProcess(t);

        log.info("Processed result: {}", JSONUtil.toJsonStr(result));
        return result;
    }

    public abstract void volidateParams(T t) throws Exception;

    public abstract R doProcess(T t);
}
